package com.css.dbshards;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 郭辉
 * @className TODO
 * @description TODO
 * @date 2022/11/29 8:38
 * @company 海康威视
 * @since 1.0.0
 */
public class MybatisUtils {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        try {
            String resource = "mybatis-source.xml";
            InputStream resourceAsStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static SqlSession getSqlSession(){
        SqlSession sqlSession = sqlSessionFactory.openSession();
        return sqlSession;
    }

  /*  public static void main(String[] args) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        DbShardDao mapper = sqlSession.getMapper(DbShardDao.class);
        mapper.insert(new DbShardsEntity("8778f843c5cec712be47430c8916d2ad", "10000", "9bb45e1deac9f925ce1358d1ddb7fdd7", "我是db_father10000子表"));

    }*/
}
